from sortedcontainers import SortedList


class Solution:
    def canReach(self, s: str, minJump: int, maxJump: int) -> bool:
        size = len(s)

        if s[-1] == "1":
            return False

        queue = SortedList()
        queue.add((0, 0))

        for i in range(size):
            while queue and i > queue[0][1]:
                queue.pop(0)
            if not queue:
                return False
            if i < queue[0][0]:
                continue
            if s[i] == "0":
                if i == size - 1:
                    return True
                queue.add((i + minJump, i + maxJump))

        return False


if __name__ == "__main__":
    print(Solution().canReach(s="011010", minJump=2, maxJump=3))  # True
    print(Solution().canReach(s="01101110", minJump=2, maxJump=3))  # False
    print(Solution().canReach(s="0110110000110010000000", minJump=2, maxJump=3))  # False
